package by.bsu.scs_bsu.custom_tags;

import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.jsp.tagext.SimpleTagSupport;

import org.apache.log4j.Logger;

public class ParameterTag extends SimpleTagSupport {
	
	private static final Logger LOGGER = Logger.getLogger("system_logger");
	
	private String paramName;
	private String paramValue;
	private String isDirectString;
	
	public void setName(String paramName) {
		this.paramName = paramName;
	}
	
	public void setValue(String paramValue) {
		this.paramValue = paramValue;
	}
	
	public void setDirect(String isDirectString) {
		this.isDirectString = isDirectString;
	}
	
	public void doTag() {
		boolean isDirect;

		if(isDirectString.toLowerCase().equals("true")) {
			isDirect = true;
		} else {
			isDirect = false;
		}
		try {
			if(paramName != null) {
				ArrayList<Parameter> parameters = ((ScreenTag) getParent()).getParamaters();
				if(parameters != null) {
					Parameter p = new Parameter(paramName, paramValue, isDirect);
					parameters.add(p);
				} else {
	                LOGGER.debug("ParameterTag: parameters do not exist.");
	            }
			}
		} catch(Exception e) {
			LOGGER.error("ParameterTag:" + e.toString());
		}
	}
}
